﻿using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OnWork.Admin.BLL.System;
using OnWork.Admin.DAL.System;

namespace OnWork.Admin.System
{
    /// <summary>
    /// 测试数据
    /// </summary>
    public class DemoController : BaseSystemController
    {
        private DemoBLL _demoBLL;

        private IHttpContextAccessor _accessor;

        /// <summary>
        /// 构造函数注入
        /// </summary>
        /// <param name="demoBLL"></param>
        public DemoController(DemoBLL demoBLL)
        {
            _demoBLL = demoBLL;
        }

        /// <summary>
        /// 获取全部
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public object GetList()
        {
            return _demoBLL.Queryable().ToList();
        }

        /// <summary>
        /// 测试添加数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public object Add()
        {
            return _demoBLL.Add(new DemoEntity { Name = "333", Value = "90" });
        }

        /// <summary>
        /// token测试
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public object GetToken()
        {
            return HttpContext.GetTokenAsync("access_token");
        }

        /// <summary>
        /// token测试
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public object GetToken2()
        {
            var test = HttpContext.User;
            return Request.Headers["Authorization"];
        }

        /// <summary>
        /// token测试
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public object GetToken3()
        {
            return _demoBLL.GetToken();
        }
    }
}